home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / pupworld.swf / scripts / __Packages / pi / Hashtable.as < prev   
Encoding:
Text File  |  2011-06-09  |  1.5 KB  |  78 lines

  1. class pi.Hashtable
  2. {
  3.    var table;
  4.    var keys;
  5.    var vals;
  6.    function Hashtable()
  7.    {
  8.       this.clear();
  9.    }
  10.    function addItem(key, val)
  11.    {
  12.       this.table[key] = val;
  13.       this.keys.push(key);
  14.       this.vals.push(val);
  15.    }
  16.    function removeItem(key)
  17.    {
  18.       var _loc2_ = 0;
  19.       while(_loc2_ < this.keys.length)
  20.       {
  21.          if(this.keys[_loc2_] == key)
  22.          {
  23.             this.keys.splice(_loc2_,1);
  24.             this.vals.splice(_loc2_,1);
  25.             break;
  26.          }
  27.          _loc2_ = _loc2_ + 1;
  28.       }
  29.    }
  30.    function getItem(key)
  31.    {
  32.       return this.table[key];
  33.    }
  34.    function clear()
  35.    {
  36.       this.table = new Array();
  37.       this.keys = new Array();
  38.       this.vals = new Array();
  39.    }
  40.    function duplicate()
  41.    {
  42.       var _loc3_ = new pi.Hashtable();
  43.       var _loc2_ = 0;
  44.       while(_loc2_ < this.keys.length)
  45.       {
  46.          _loc3_.addItem(this.keys[_loc2_],this.vals[_loc2_]);
  47.          _loc2_ = _loc2_ + 1;
  48.       }
  49.       return _loc3_;
  50.    }
  51.    function containsKey(key)
  52.    {
  53.       var _loc2_ = 0;
  54.       while(_loc2_ < this.keys.length)
  55.       {
  56.          if(this.keys[_loc2_] == key)
  57.          {
  58.             return true;
  59.          }
  60.          _loc2_ = _loc2_ + 1;
  61.       }
  62.       return false;
  63.    }
  64.    function containsValue(val)
  65.    {
  66.       var _loc2_ = 0;
  67.       while(_loc2_ < this.vals.length)
  68.       {
  69.          if(this.vals[_loc2_] == val)
  70.          {
  71.             return true;
  72.          }
  73.          _loc2_ = _loc2_ + 1;
  74.       }
  75.       return false;
  76.    }
  77. }
  78.